package test.spider;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

public class App3 {
	
	static ExecutorService threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
	
	static AtomicInteger count = new AtomicInteger(0);
	
	public static void main(String[] args) {
		for(int i=0;i<10;i++) {
			int j = i;
			count.incrementAndGet();
			threadPool.submit(new Runnable() {
				@Override
				public void run() {
					System.out.println(j);
//					count.incrementAndGet();
					threadPool.submit(new Runnable() {
						
						@Override
						public void run() {
							System.out.println(j+"x");
						}
					});
				}
			});
		}
		
		threadPool.shutdown();
		
		Runtime.getRuntime().addShutdownHook(new Thread() {
			@Override
			public void run() {
				System.out.println(count.get());
			}
		});
		
		/*while(true) {
			if(count.get()==20) {
				threadPool.shutdown();
				break;
			}
		}*/
		
	}

}
